import { defineStore } from 'pinia'
import { RouteRecordRaw } from 'vue-router'
import { constantRoutes } from '@/router/index'
import { piniaPersistConfig } from '../index'

type stateType = {
  menuData: RouteRecordRaw[]
  sideOpenFlag: Boolean
  refreshFlag: Boolean
}
// 整个应用的状态
const useAppStore = defineStore('app', {
  state(): stateType {
    return {
      // 固定路由
      menuData: constantRoutes,
      // 菜单是否打开
      sideOpenFlag: true,
      // 刷新路由标识，true展示 false销毁
      refreshFlag: true
    }
  },
  actions: {
    setRefreshFlag(payload: Boolean) {
      this.refreshFlag = payload
    }
  },
  persist: piniaPersistConfig('app', ['sideOpenFlag'])
})
export default useAppStore
